package com.sanyang.lawyer.controller.adm;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.sanyang.lawyer.entity.Adm_Address;
import com.sanyang.lawyer.entity.Adm_Dispatch;
import com.sanyang.lawyer.entity.Hr_emp;
import com.sanyang.lawyer.service.adm.AdmAddressService;
import com.sanyang.lawyer.service.hr.HrEmpService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * @program: lawyer
 * @description: 通讯录的Controller层
 * @author: Mr.Wang
 * @create: 2019-10-29 08:40
 **/
@RestController
@RequestMapping("address")
public class AdmAddressController {
    @Autowired
    private HrEmpService empService;

    @Autowired
    private AdmAddressService address;

    @RequestMapping("empinfo")
    public List<Hr_emp> info(){
        List<Hr_emp> list=empService.empquery();
        return list;
    }

    @RequestMapping("empfurry")
    public List<Hr_emp> empfurry(String empname){
        List<Hr_emp> list=empService.empfy(empname);
        return list;
    }

    @RequestMapping("addressquery")
    public Hr_emp addressquery(int id){
        Hr_emp emp=empService.getById(id);
        return emp;
    }

    @RequestMapping("addressinfo")
    public List<Adm_Address> addressinfo(){
        List<Adm_Address> admAddress=address.listall();
        return admAddress;
    }

    @RequestMapping("addressgetbyid")
    public Adm_Address addressgetbyid(int id){
        Adm_Address admAddress=address.getbyid(id);
        return admAddress;
    }

    @RequestMapping("addressdelete")
    public String addressdatele(int id){
        address.delete(id);
        return "1";
    }

    @RequestMapping("addressinsert")
    public String addressinsert(@RequestParam("data") String data) throws IOException {
        Adm_Address adm=new  Adm_Address();
        ObjectMapper objectMapper = new ObjectMapper();
        Adm_Address es=objectMapper.readValue(data,adm.getClass());
        address.insert(es);
        return "1";
    }

    @RequestMapping("addressupdate")
    public String addressupdate(@RequestParam("data") String data) throws IOException {
        Adm_Address adm=new  Adm_Address();
        ObjectMapper objectMapper = new ObjectMapper();
        Adm_Address es=objectMapper.readValue(data,adm.getClass());
        address.update(es);
        return "1";
    }

    @RequestMapping("addressfurry")
    public List<Adm_Address> addressfurry(String aname){
        List<Adm_Address> list=address.furry(aname);
        return list;
    }



}
